<template>
  <div class="mod-fii__fiicompany">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.company" placeholder="集团名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('fii:fiicompany:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('fii:fiicompany:delete')" type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="company" label="集团名称" header-align="center" align="center"></el-table-column>
      <el-table-column prop="type" label="企业类型" header-align="center" align="center">
        <template v-slot="scope">
          <template v-for="(itemDict, i) in dict.type" :key="i" :hehe="111">
            <el-tag v-if="scope.row.type == parseInt(itemDict.code)" size="small">{{ itemDict.name }}</el-tag>
          </template>
        </template>
      </el-table-column>
      <el-table-column prop="taxNo" label="税号" header-align="center" align="center"></el-table-column>
      <el-table-column prop="address" label="地址" header-align="center" align="center"></el-table-column>
      <el-table-column prop="contacts" label="联系人" header-align="center" align="center"></el-table-column>
      <el-table-column prop="phone" label="联系人电话" header-align="center" align="center"></el-table-column>
      <el-table-column prop="spaceSize" label="私域空间大小（M）" header-align="center" align="center"> </el-table-column>
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="230">
        <template v-slot="scope">
          <el-button v-if="hasPermission('fii:fiicompany:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('fii:fiicompany:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
          <el-button v-if="hasPermission('fii:fiicompany:delete')" type="text" size="small" @click="addCourse(scope.row.id)">添加课程</el-button>
          <el-button v-if="hasPermission('fii:fiicompany:update')" type="text" size="small" @click="addAccountsMethod(scope.row)">生成账号</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <!-- 生成账号 -->
    <add-accounts v-if="addAccountsVisible" ref="addAccounts" @refreshDataList="getDataList"></add-accounts>
    <!-- 分配的课程 -->
    <el-drawer title="分配课程" v-model="courseVisible" :size="800" close-on-press-escape="false" custom-class="rr-drawer"> <CourseList :companyId="companyId" ref="courseList"></CourseList></el-drawer>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, nextTick, reactive, toRefs } from "vue";
import AddOrUpdate from "./fiicompany-add-or-update.vue";
import AddAccounts from "./account-add-accounts.vue";
import CourseList from "./fiicompanycourse.vue";
import Account from "@/views/mp/account.vue";
import { IObject } from "@/types/interface";
import baseService from "@/service/baseService";
export default defineComponent({
  components: {
    AddOrUpdate,
    CourseList,
    AddAccounts
  },
  setup() {
    const state = reactive({
      addAccounts: AddAccounts,
      courseList: CourseList,
      companyId: 0,
      courseVisible: false,
      dict: {
        type: baseService.strDict("1:连锁企业,2:独立学校")
      },
      getDataListURL: "/fii/fiicompany/page",
      getDataListIsPage: true,
      exportURL: "/fii/fiicompany/export",
      deleteURL: "/fii/fiicompany",
      deleteIsBatch: true,
      addAccountsVisible: false,
      dataForm: {
        company: ""
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  methods: {
    addCourse(id: number) {
      this.companyId = id;
      // this.courseList.initQuery(id);
      nextTick(() => {
        if (this.courseList) {
          // this.courseList.dataForm.id=id+"";
          // this.courseList.dataForm.companyId=id+"";
          this.courseVisible = true;
        }
      });
    },
    addAccountsMethod(row: IObject) {
      this.addAccountsVisible = true;
      nextTick(() => {
        if (this.addAccounts && !this.addAccounts.visible) {
          this.addAccounts.dataForm.companyId = row.id;
          this.addAccounts.init();
        }
      });
    }
  },
  watch: {}
});
</script>
